<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/include/common-base.jsp"%>
  <title>定时任务管理</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  
  <!-- left start -->
  <%@include file="/common/plateform/left-project.jsp" %>
  <!-- left end-->
	<c:set var="sysEname" value="${param.sysEname}"/>
  <!-- Main start -->
  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">

        <div class="box box-success">
            <!--列表title  start --> 
	        <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i> 定时任务列表 
                 　　　		<button  onclick="toAdd();" class="btn btn-primary" type="button"><i class="fa fa-plus-circle"></i> 增加任务 </button>
                    <button  onclick="executeTask('','start');" class="btn btn-success" type="button"><i class="fa fa-plus-circle"></i> 启动全部任务 </button>
                    <button  onclick="executeTask('','stop');" class="btn btn-danger" type="button"><i class="fa fa-plus-circle"></i> 停止全部任务 </button>
                 </h3>
            </div>
            
            <!-- /.box-header -->
            <div class="box-body">
              <table id="dataList" class="table table-bordered table-hover" >
                <thead class="bg-success">
                <tr>
                  <th>名称/描述</th>
                  <th>间隔 时:分:秒</th>
                  <th>启止时点</th>
                  <th>间隔类型</th>
                  <th>开启类型</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="dataList-body">
                </tbody>
              </table>
            </div>
          </div>
        </div>
        	
<script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
			<tr>
				<td>
				<?=strUtil.doNull(rows[i].description,'')?><br/>
				<?=strUtil.doNull(rows[i].className,'')?>
				</td>
				<td><?=rows[i].hour?>:<?=rows[i].minute?>:<?=rows[i].second?></td>
				<td><?=rows[i].startTime?>--<?=rows[i].endTime?></td>
                <td><?if(rows[i].intervalType=='0'){?>时间<?}else{?>每天<?}?></td>
                <td><?if(rows[i].taskStatus=='0'){?>手动开启<?}else{?>自动开启<?}?></td>
				<td><?if(rows[i].openStart==true){?><font color='green'>开启</font><?}else{?><font color='red'>未开启</font><?}?></td>
				<td>
            <?if(rows[i].openStart==true){?>
					<button type="button" class="btn btn-danger btn-xs" onclick="executeTask('<?=rows[i].taskKey?>','<?=rows[i].serverIp?>','stop')">关闭</button>
            <?}else{?>
					<button type="button" class="btn btn-success btn-xs" onclick="executeTask('<?=rows[i].taskKey?>','<?=rows[i].serverIp?>','start');">开启</button>
					<?if(rows[i].openStart==false){?><button type="button" class="btn btn-warning btn-xs" onclick="editInfo('<?=rows[i].taskKey?>','<?=rows[i].openStart?>','<?=rows[i].serverIp?>');">修改</button>
                    <button type="button" class="btn btn-danger btn-xs" onclick="delInfo('<?=rows[i].taskKey?>','<?=rows[i].openStart?>','<?=rows[i].serverIp?>');">删除</button><?}?>
            <?}?>
				</td>
			</tr>
		<?}?>
</script>
<script>
var clickMenu = "task-list";
isShowLog = true;
var sysEname="${param.sysEname}";

$(function () {
	//1、加载分页列表数据
	getTableData1();
	
 });
//打开添加页面
function toAdd(){
	//cleanData("submitFormData");//清空模态窗口内数据
	mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
	//doAdd("my_modal");
	$('#my_modal').modal('show');
}
//逻辑删除
function delInfo(id,ip){
    var index_submit = layer.confirm('您确定要删除信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
        , function(){
            layer.close(index_submit);
            $.ajax({
                type: "post",
                url: "${ctx}/task/del.action",
                data:{"key":id,"sysName":sysEname,"serverIp":ip},
                dataType: "json",
                success: function(data){
                    var result = data;//jQuery.parseJSON(data);
                    if(result.flag=='T'){
                        getTableData1();
                    }else{
                        layer.alert("删除失败！");
                    }
                }
            });
        });
}

function executeTask(taskKey,serverIp,type){
	var url ="${ctx}/task/stop.action";
	if("start"==type){
		url ="${ctx}/task/start.action";
	}
	var index_submit = layer.confirm("您确定要["+type+"]吗？", {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
			type: "post",
			url: url,
            data:{"key":taskKey,"sysName":sysEname,"serverIp":serverIp},
			dataType: "json",
			success: function(data){
				var result = data;//jQuery.parseJSON(data);
				if(result.flag=='T'){
					layer.alert("操作成功！");
					getTableData1();
				} else{
					layer.alert("删除失败！");	
				}
			}
		});
	});
}

//读取（查询、编辑）数据
function editInfo(id,openStatus,ip){
        var url = '${ctx}/task/add.action';
        mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
        $.ajax({
            type:'get',
            url:url,
            data:{"key":id,"sysName":sysEname,"serverIp":ip},
            async:false,
            dataType:"json",
            success: function(myData){
                console.log(myData);
                //反显加载数据
                FormUtil.loadView("task", myData);
                $('#my_modal').modal('show');
            }
        });
}
//反显数据${ctx}/task/save.action
function saveTask(formId){
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
		    type:'post',
		    url:'${ctx}/task/save.action',
		    data:$("#"+formId).serialize(),
		    async:false,
		    dataType:'json',
		    success: function(myData){ 
		     console.log(myData);
		        if(myData.flag=="T"){
		        	result = myData;
		        	$('#my_modal').modal('hide');
		        	getTableData1();
		    	}else{
		     		layer.alert(myData.msg);
		    	}
		  	}
		});	
	});
}

//加载列表数据
function getTableData1(){
//	deleteAllRow(dataListId);
	$.ajax({
		   type:'get',
		   url:'${ctx}/task/list!data.action?sysName='+sysEname,
		   dataType:'json',
		   success: function(myData){
		     console.log(myData);
		     if(myData.total=="0"){
                 $("#dataList-body").html("");
             }else{
                 var data = baidu.template("dataList-template",eval(myData));
                 $("#dataList-body").html(data);
			 }
		   }
		});	
  }
</script>
<script src="/js/tools-objname.js"></script>

   <div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-dialog" style="width:900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title">
							<font color="red">添加/修改</font>&nbsp;
						</h4>
					</div>
					<div class="modal-body">
				
					   <form class="form-horizontal addFormBody" role="form" id="submitForm">
					   		<!-- 隐藏域 start -->
							<input type="hidden" class="formToken"  name="formToken" />
							<input type="hidden" class="clean" name="taskKey" data-name="task.taskKey"/>
					         <!-- 隐藏域 end -->
					         
					        <div class="box-body" id="submitFormData">
					          	<!-- 属性循环体 start -->
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >任务名称</label>
				                  <div class="col-sm-8">
				                    <input type="text"  data-name="task.className" name="className" class="form-control clean" maxlength="100" placeholder="必填项，输入英文class地址" />
				                  </div>
				                </div>
								<div class="form-group">
									<label class="col-sm-3 control-label" >所属系统</label>
									<div class="col-sm-8">
										<input type="text" value="${param.sysEname}" data-name="task.sysName" name="sysName" class="form-control" maxlength="100" placeholder="必填项，输入所属系统标识" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label" >启用任务IP</label>
									<div class="col-sm-8">
										<input type="text"  data-name="task.serverIp" name="serverIp" class="form-control clean" maxlength="100" placeholder="必填项，输入启用任务IP地址" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label" >任务类型</label>
									<div class="col-sm-8">
										<select name="taskType" id="taskType" data-name="task.taskType" class="form-control clean">
											<option value="" selected="selected">自定义类</option>
											<option value="remote">远程调用</option>
										</select>
									</div>
								</div>
				                
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >间隔时间</label>
				                  <div class="col-sm-8">
				                  	 小时:<input title="0~23" data-name="task.hour" name="hour" data-options="required:true,validType:'number'" size="10" />
								        分钟:<input title="0~59" data-name="task.minute" name="minute" data-options="required:true,validType:'number'" size="10" />
								        秒<input title="0~59" data-name="task.second" name="second" data-options="required:true,validType:'number'" size="10" />
				                  </div>
				                </div>
				                
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >间隔类型</label>
				                  <div class="col-sm-8">
				                    <select name="intervalType" data-name="task.intervalType"  id="intervalType" class="form-control clean">
				                        <option value="">--请选择--</option>
										   <option value="0">时间</option>
										   <option value="1">每天</option>
				                    </select>
				                  </div>
				                </div>
				                
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >开启类型</label>
				                  <div class="col-sm-8">
				                    <select name="taskStatus" id="taskStatus" data-name="task.taskStatus" class="form-control clean">
					                    <option value="0" selected="selected">手动开启</option>
					                    <option value="1">自动开启</option>
				                    </select>
				                  </div>
				                </div>
				                
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >启止时点</label>
				                  <div class="col-sm-8">
				                                    开始:<input title="0~23" data-name="task.startTime" name="startTime" data-options="required:true,validType:'number'" size="10" />
						                     结束:<input title="0~23" data-name="task.endTime" name="endTime" data-options="required:true,validType:'number'" size="10" />
				                  </div>
				                </div>
				                
				                <div class="form-group">
				                  <label class="col-sm-3 control-label" >描&nbsp;&nbsp;&nbsp;&nbsp;述</label>
				                  <div class="col-sm-8">
				                    <input type="text"  data-name="task.description" name="description" class="form-control clean" maxlength="100" placeholder="必填项" />
				                  </div>
				                </div>
				                <!-- 属性循环体 end -->
					        </div>
					        
			                <div class="box-footer">
				                <button type="button" class="btn btn-success pull-left" onclick="cannel('');">取消</button>
				                <button type="button" class="btn btn-danger pull-right" onclick="saveTask('submitForm');">提 交</button>
				            </div>
				            
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
    </div>


      </div>
    </section>
    <!-- Main end -->
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
  <%@include file="/common/plateform/foot.jsp" %>
  <!-- foot start -->
  


</body>
</html>
